package com.stark.core.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

import org.hibernate.validator.constraints.Length;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.stark.core.properties.Constants;
import com.stark.core.validator.UpdateGroup;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 用户。
 * @author Ben
 * @since 2.0.0
 * @version 1.0.0
 */
@Entity
@Table
@Data
@Accessors(chain = true)
@ApiModel("用户")
public class User implements Serializable {
	
	private static final long serialVersionUID = -4162511277454867941L;
	
	public static final Sort DEFAULT_SORT = Sort.by(Direction.ASC, "id");

	/** 自增主键 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@NotNull(groups = UpdateGroup.class)
	@ApiModelProperty("主键")
	private Long id;

    /** 用户名称 */
	@Column(length = 100)
	@Length(max = 100)
	@NotBlank
	@ApiModelProperty("用户名称")
    private String username;

    /** 密码 */
	@Column(length = 100)
	@Length(max = 100)
	@NotBlank
	@ApiModelProperty("密码")
    private String password;
	
	/** 姓名 */
	@Column(length = 100)
	@Length(max = 100)
	@ApiModelProperty("姓名")
    private String name;
	
	/** 性别: 0-男,1-女,2-其他 */
	@Column
	@ApiModelProperty(value = "性别: 0-男,1-女,2-其他", allowableValues = "0,1,2")
	private Integer sex;

    /** 出生日期 */
	@Column
	@Past
	@DateTimeFormat(pattern = Constants.PATTERN_DATE)
	@JsonFormat(pattern = Constants.PATTERN_DATE, timezone = "GMT+8")
	@ApiModelProperty("出生日期")
    private Date birthday;

}
